package com.edmond.controller;

import com.edmond.entity.Order;
import com.edmond.entity.OrderVO;
import com.edmond.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderHandler {

    @Autowired
    private OrderRepository orderRepository;

    //  新增订单信息
    @PostMapping("/save")
    public void save(@RequestBody Order order) {
        System.out.println(order);
        orderRepository.save(order);
    }

    //  根据用户 id 查询所有订单信息
    @GetMapping("/findAllByUid/{uid}/{index}/{pageSize}")
    public OrderVO findAllByUid(@PathVariable("uid") long uid, @PathVariable("index") Integer index, @PathVariable("pageSize") Integer pageSize) {
        OrderVO orderVO = new OrderVO();
        orderVO.setCode(0);
        orderVO.setMsg("success");
        orderVO.setCount(orderRepository.countByUid(uid));
        orderVO.setData(orderRepository.findAllById(uid, index, pageSize));
        return orderVO;
    }
}
